from math import sqrt
n = int(input())

if n >= 1000  and n <= 9999:

   a=n % 10
   b=n //10 % 10
   c=n //100 % 10
   d=n //1000

   ab= a*10 + b
   bc= b*10 + c
   cd= c*10 + d

   abc = n // 10
   bcd = n - d * 1000

   for i in range (2, a//2+1):
       o = a % i
       if o == 0:
            a = 0
       else:
            i += 1

   for i in range (2, b//2+1): #b
       o = b % i
       if o == 0:
            b = 0
       else:
            i += 1

   for i in range (2, c//2+1): #c
       o = c % i
       if o == 0:
           c = 0
       else:
           i += 1

   for i in range (2, d//2+1):#d
       o = d % i
       if o == 0:
           d = 0
       else:
           i += 1

   for i in range (2, ab//2+1): #ab
       o = ab % i
       if o == 0:
           ab = 0
       else:
           i += 1

   for i in range (2, bc//2+1): #bc
       o = bc % i
       if o == 0:
           bc = 0
       else:
           i += 1

   for i in range (2, cd//2+1): #cd
       o = cd % i
       if o == 0:
            cd = 0
       else:
            i += 1

   for i in range (2, n//2+1): #n
        o = n % i
        if o == 0:
             n = 0
        else:
            i += 1

   for i in range (2, abc//2+1): #abc
        o = abc % i
        if o == 0:
               abc = 0
        else:
           i += 1

   for i in range (2, bcd//2+1): #bcd
        o = bcd % i
        if o == 0:
              bcd = 0
        else:
              i += 1
   print(max(a,b,c,d,ab,bc,cd,abc,bcd,n))
else:
     print("0")